﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using Web.Support;
using System.Web.Security;

namespace Web.Support
{
    public abstract class BaseHandler :IHttpHandler,IUserProfile
    {
        public virtual bool IsReusable
        {
            get { return false; }
        }

        public virtual void ProcessRequest(HttpContext context)
        {
            UserLoggedIn = "Anonymous";
            //SubSectorName = string.Empty;

            if (HttpContext.Current.User != null)
            {
                if (HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    UserLoggedIn = context.User.Identity.Name;

                    if (HttpContext.Current.User.Identity is FormsIdentity)
                    {
                        FormsIdentity id = HttpContext.Current.User.Identity as FormsIdentity;
                        FormsAuthenticationTicket ticket = id.Ticket;

                        string userData = ticket.UserData.Trim();
                        if (!string.IsNullOrEmpty(userData))
                        {
                            string[] datas = userData.Split('|');

                            UserID = int.Parse(datas[0]);

                            if (!string.IsNullOrEmpty(datas[1]))
                                GroupID = Convert.ToInt32(datas[1]);

                            if (!string.IsNullOrEmpty(datas[2]))
                                GroupAppID = (datas[2].ToString());

                            if (!string.IsNullOrEmpty(datas[3]))
                                UserCode = datas[3].ToString();

                        }
                    }
                }
            }

        }

        public string UserLoggedIn { get; set; }
        public string UserCode { get; set; }
        public int UserID { get; set; }
        public int GroupID { get; set; }
        public string GroupAppID { get; set; }
    }
}